<?php

/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

  defined('_JEXEC') or die('Retricted Access');
  
  JHTML::_('behavior.tooltip');
  $selected_employer = JRequest::getVar('selected');
  if ($selected_employer)
  	$selected_employer = explode(',',$selected_employer);
  else 
  	$selected_employer = array();
?>

	
<script type="text/javascript">
/* <![CDATA[ */
	var employer_number = <?php echo count($this->items); ?>;
	var list_employer = '';
	var list_name = '';
	function select_multi_empoyer()
	{
		for (i=0;i<=employer_number;i++)
		{
			chk_obj = document.getElementById('cb'+i);
			if (chk_obj)
				if (chk_obj.checked)
				{
					selected_str = chk_obj.value;
					selected_value = selected_str.substring(0,selected_str.indexOf('_'));
					selected_name = selected_str.substring(selected_str.indexOf('_')+1,selected_str.length);
					if (list_employer)
					{
						list_employer += ',' + selected_value;
						list_name += ',' + selected_name;
					}
					else
					{
						list_employer += selected_value;
						list_name += selected_name;
					}
						
				}
		}
		if(list_employer==''){
			alert('<?php echo JText::_('Please select employer!')?>');
			return;
		}
		assign_user(list_employer,list_name);
	}
	
	function assign_user(user_id,user_name)
	{
		s_selected_employer = window.parent.$('s_selected_employer');
		
		if (!user_id)
		{
			s_selected_employer.innerHTML = '';
			window.parent.$('job_author').value = '';
			if (window.parent.$('sbox-window'))
				window.parent.$('sbox-window').close();
			return;
		}
		window.parent.$('job_author').value = user_id;
		var temp_userid = user_id;
		arr_user_id = new Array();
		count_span = 0;
		while (user_id.indexOf(',')!=-1)
		{
			count_span++;
			temp = user_id.substring(0,user_id.indexOf(','));
			user_id = user_id.substring(user_id.indexOf(',') + 1,user_id.length);
			arr_user_id[count_span] = temp;
		}
		arr_user_id[count_span + 1] = user_id;
		user_id = temp_userid;
		
		window.parent.$('job_author').value = user_id;	
		
		s_selected_employer.innerHTML = '';
		var display_text = '';
		count_span = 0;
		while (user_name.indexOf(',')!=-1)
		{
			count_span ++;
			temp = user_name.substring(0,user_name.indexOf(','));
			user_name = user_name.substring(user_name.indexOf(',') + 1,user_name.length);
			display_text += '<span id="selection'+count_span + '">' + temp + '<a href="javascript:void(0)" onclick="remove_emp('+arr_user_id[count_span] +',\'selection'+count_span+'\')">'+'<img src="' + '<?php echo JURI::root(); ?>' + 'components/com_jajobboard/images/del.gif" alt="Delete" />'+'</a>' + '</span>';
		}
		count_span ++;
		display_text += '<span id="selection'+count_span + '">' + user_name + '<a href="javascript:void(0)" onclick="remove_emp('+arr_user_id[count_span] +',\'selection'+count_span+'\')">'+'<img src="' + '<?php echo JURI::root(); ?>' + 'components/com_jajobboard/images/del.gif" alt="Delete" />'+'</a>' + '</span>';
		
		display_text = display_text.replace(new RegExp("REPLACE", "g"), ",");
				
		s_selected_employer.innerHTML  = display_text;
		if (window.parent.$('sbox-window'))
			window.parent.$('sbox-window').close();
	}	
	
/* ]]> */
</script>
<form name="adminForm" action="<?php echo JURI::root();?>index.php?option=com_jajobboard&view=jajobalerts&layout=element_user&tmpl=component&Itemid=<?php echo JRequest::getVar('Itemid'); ?>&selected=<?php echo JRequest::getVar('selected'); ?>&limitstart=<?php echo JRequest::getVar('limitstart',0) ?>" method="post">
    <div style="width:100%;">
		<table class="tablelist" width="100%">
        <tr>
      
        <td valign="top">
        <table width="100%">
			<tr>
				<td align="left" width="50%">
					<?php echo JText::_( 'Filter' ); ?>:
					<input type="text" name="user_search" id="user_search" value="<?php echo $this->search;?>" class="text_area" onchange="document.adminForm.submit();" />					
                    <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
					<button onclick="document.getElementById('user_search').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
				</td>
				<td style="text-align:right !important;" width="50%">
					<input type="button" name="<?php echo JText::_('Select'); ?>" value="select" onclick="select_multi_empoyer()"/>
					<input type="button" name="<?php echo JText::_('Cancel'); ?>" value="cancel" onclick="window.parent.cancel_select_employer()"/>
				</td>
			</tr>
		</table>
       
		<table class="tablelist">
        	<thead>
				<tr>
					<td class="sectiontableheader" width="20">
						<?php echo JText::_( 'NUM' ); ?>
					</td>
					<td width="20" class="sectiontableheader">
						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
					</td>
					<td class="sectiontableheader">            		
<!--            			<?php echo JHTML::_('grid.sort',   JText::_('Name'), 'name',@$this->lists['order_Dir'], @$this->lists['order']); ?>-->
						<?php echo JText::_('Name'); ?>
            		</td>
					
            	</tr>
			</thead>
			<tbody>
        	<?php
        	$items = $this->items;
        	for($i = 0, $orderNo=0, $n = count($items); $i < $n; $i++, $orderNo++){
        		$item = $items[$i];
        		$item->company = str_replace(",", "REPLACE", $item->company);
        	?>
        	<tr class="sectiontableentry<?php echo $i%2 +1 ; ?>">
        		<td>
        			<?php echo $i + 1 + $this->pagination->limitstart; ?>
        		</td>
        		<td style="text-align:center !important">
        			<input <?php if (in_array($item->id,$selected_employer)) echo 'checked="checked"'; ?> id="cb<?php echo $i?>" type="checkbox" onclick="isChecked(this.checked); " value="<?php echo $item->id.'_'.$item->company; ?>" name="cid[]"/>
        		</td>
        		<td>
        			<a style="cursor: pointer;" href="#" onclick="assign_user('<?php echo $item->id; ?>','<?php echo $item->company; ?>');"><?php echo str_replace("REPLACE", ",", $item->company); ?> </a>
        		</td>
        	</tr>	
        	<?php
        		
			}
        	?>
        	<tbody>
        	<tfoot>
				<tr>
					<td style="text-align:center !important" colspan="9">
						<?php echo $this->pagination->getListFooter(); ?>
					</td>
				</tr>
			</tfoot>
		</table>
        </td>
        </tr>
        </table>
        
	</div>
	<input type="hidden" name="option" value="<?php echo 'com_jajobboard'; ?>" />
	<input type="hidden" name="view" value="jajobalerts" />
	<input type="hidden" name="layout" value="element_user" />
	<input name="tmpl" value="component" type="hidden" />
	<input type="hidden" name="boxchecked" value="" />
    <input type="hidden" name="task" value="" />
	<!--<input type="hidden" name="table_name" value="<?php echo $this->table_name;?>" />-->
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
<script type="text/javascript">
/* <![CDATA[ */
 
 	function load_page()
	{
		selected = window.parent.document.getElementById('job_author').value;
		for (i=0;i<employer_number;i++)
		{
			ele = document.getElementById('cb'+i);
			if (ele)
				tmp = ele.value;
			else
				tmp = '';
			if (tmp)
			{
				tmp = tmp.substring(0,tmp.indexOf('_'));
				
			}
			if (selected.indexOf(tmp)!=-1)
				ele.checked = true;
			else
				ele.checked = false;
			
		}
	}
	load_page();
/* ]]> */
</script>